package cate.game.play.skill.passive.hero;

import cate.game.play.config.PlayCfgArgs;
import cate.game.play.fighter.Fighter;
import cate.game.play.proce.action.ctx.ActionCtx;
import cate.game.play.skill.passive.PassiveHandler;

import java.util.HashSet;
import java.util.Set;

/**
 * 场上每次有英雄死亡，回复自身15%生命值，同时获得1层【灵魂共生】，一回合内，同一单位多次死亡只算1次
 */
public class 灵魂漩涡PH extends PassiveHandler {

	private double 回复系数;

	private int buff;

	//回复系数=1500&buff=？？
	@Override
	public void parse(String code) {
		PlayCfgArgs args = new PlayCfgArgs(code);
		回复系数 = args.getWDouble("回复系数", 0d);
		buff = args.getInt("buff", 0);
	}

	@Override
	public void parseExt(String code) {
		PlayCfgArgs args = new PlayCfgArgs(code);
		回复系数 += args.getWDouble("回复系数", 0d);
	}

	private Set<Integer> pids = new HashSet<>();

	@Override
	public void onRoundBegin(ActionCtx action) {
		pids.clear();
	}

	@Override
	public void onOtherDead(ActionCtx action, Fighter killer, Fighter deader) {
		if (skill.owner.isDead()) {
			return;
		}
		if (pids.contains(deader.getPid())) {
			return;
		}
		skill.owner.attr.passiveHeal(action, skill.owner.attr.total().hpTotal() * 回复系数);
		skill.owner.buff.tryAddByTid(action, buff);
		pids.add(deader.getPid());
	}
}
